package com.lanou.zy.projecta.activity;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.zy.projecta.R;

import java.util.Random;

public class SplashActivity extends AppCompatActivity {

    private ImageView SplashIv, translationIv;
    private TextView translationTv;
    private Handler handler;
    private Animation left_in;
    private Animation right_out;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        initView();
//        TransIn();
//        TransOut();
        initData();
    }

    private void TransOut() {
        handler = new Handler(new Handler.Callback() {
            @Override
            public boolean handleMessage(Message msg) {
                translationIv.setAnimation(right_out);
                translationTv.setAnimation(right_out);
                return false;
            }
        });
        handler.sendEmptyMessageDelayed(100, 3000);
    }

    private void TransIn() {
        handler = new Handler(new Handler.Callback() {
            @Override
            public boolean handleMessage(Message msg) {
                translationIv.setAnimation(left_in);
                translationTv.setAnimation(left_in);
                return false;
            }
        });
        handler.sendEmptyMessageDelayed(100, 1000);
    }


    private void initView() {
        translationIv = (ImageView) findViewById(R.id.translationIv);
        translationTv = (TextView) findViewById(R.id.translationTv);

//        translationIv.setVisibility(View.VISIBLE);
//        translationTv.setVisibility(View.VISIBLE);
//        left_in = AnimationUtils.loadAnimation(this, R.anim.left_in);
//        right_out = AnimationUtils.loadAnimation(this, R.anim.right_out);


//        int iv[] = new int[3];
//        int num;
//        iv[0] = R.mipmap.splash1;
//        iv[1] = R.mipmap.splash2;
//        iv[2] = R.mipmap.splash3;
        SplashIv = (ImageView) findViewById(R.id.SplashIv);

//        Random random = new Random ();
//        num = random.nextInt(2 - 0 + 0) + 1;
//        SplashIv.setBackgroundResource(iv[num]);
    }

    private void initData() {

        handler = new Handler(new Handler.Callback() {
            @Override
            public boolean handleMessage(Message msg) {
                Intent intent = new Intent();

                intent.setClass(SplashActivity.this, MainActivity.class); // 跳转到登录页面
                startActivity(intent);
                overridePendingTransition(R.anim.right_in, R.anim.left_out);
                finish(); // 关闭当前页面


                return false;
            }
        });
        handler.sendEmptyMessageDelayed(100, 2000);

    }


}
